package cn.itcast.service.impl;


import cn.hutool.core.util.ObjectUtil;
import cn.itcast.dao.Sys_roleDao;
import cn.itcast.entity.PageResult;
import cn.itcast.pojo.Role;
import cn.itcast.service.Sys_roleService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
public class Sys_roleServiceImpl implements Sys_roleService {
    @Autowired
    private Sys_roleDao sysRoleDao;


    @Override
    public PageResult queryRoleList(Integer page, Integer pageSize, String queryString) {
        PageHelper.startPage(page,pageSize);
        Page<Role> roles = this.sysRoleDao.selectByCondition(queryString);

        return new PageResult(roles.getTotal(),roles);
    }

    @Override
    public List<Role> queryRoleList(Integer page, Integer pageSize) {
        return this.sysRoleDao.findAll();
    }

    @Override
    public Boolean saveRoles(Map<String, String> map) {
        String name = map.get("name");
        String keywork = map.get("keywork");
        String textarea = map.get("textarea");
        Role role = new Role();
        role.setName(name);
        role.setKeyword(keywork);
        role.setDescription(textarea);
        return this.sysRoleDao.add(role);
    }

    @Override
    public Role queryEditRoles(Integer id) {
        return this.sysRoleDao.findById(id);
    }

    @Override
    public Boolean editRoles(Role role) {
        if(ObjectUtil.isNotEmpty(role)){
            return false;
        }
        return this.sysRoleDao.update(role);
    }

    @Override
    public Boolean delRoles(Integer id) {
        return this.sysRoleDao.deleteById(id);
    }

    @Override
    public List<Role> queryRolesAll() {
        List<Role> all = this.sysRoleDao.findAll();
        return all;
    }
}
